package com.lx.user.web;

import javax.servlet.http.HttpServletRequest;

import com.lx.Login.bean.LoginPropertise;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Enumeration;

@RestController
public class User {

    @RequestMapping("user")
    String user(HttpServletRequest request){
        Enumeration<String> names = request.getHeaderNames();
        while(names.hasMoreElements()){
            String name = names.nextElement();
            String head = request.getHeader(name);
            System.out.println(name + " " + head);
        }
        return "user" + request.getServerPort();
    }

    @Autowired
    LoginPropertise loginPropertise;

    @Value("${login.usernameColumn}")
    String usernameColumn;

    @RequestMapping("userProp")
    public LoginPropertise loginProper(){
        return loginPropertise;
    }














    //////////////////////////////////////////////
    @RabbitListener(queuesToDeclare = @Queue("work.queue"))
    public void recvMsg1(String msg){
        System.out.println("msg1 = " + msg);
    }

    @RabbitListener(queuesToDeclare = @Queue("work.queue"))
    public void recvMsg2(String msg){
        System.out.println("msg2 = " + msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topicQueue"),
            exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topicEx"),
            key = {"user.*", "cat.#"}
    ))
    public void TopicMsg1(String msg){
        System.out.println("msg1 = " + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topicEx"),
            key = {"user.save", "index.*"}
    ))
    public void TopicMsg2(String msg){
        System.out.println("msg2 = " + msg);
    }


}
